package tools;

import org.apache.log4j.Logger;

public class CLogger
{

	/**
	 * 
	 * @uml.property name="logger"
	 * @uml.associationEnd 
	 * @uml.property name="logger" multiplicity="(1 1)"
	 */
	protected Logger logger_ = null;
	
	/**
	 * Zalecany konstruktor logera
	* @param klasa
	*/
	public CLogger (@SuppressWarnings("rawtypes") Class klasa)
		{
			try {				
				logger_ = Logger.getLogger (klasa);
			} 
			catch (Exception e) {
				logger_ = null;
			}
		}

 public CLogger(String nazwa) {
     try {               
         this.logger_ = Logger.getLogger(nazwa);
     } 
     catch (Exception e) {
         this.logger_ = null;
     }
 }


	protected static final String BEGIN_LIST = " ('";
	protected static final String SEPARATOR  = "', '";
	protected static final String END_LIST   = "')";
	
	
	protected String notNull (Object o)
	{
		return null == o ? "null" : o.toString();
	}
	
	
	protected String format (Object [] a)
	{
		
		if (null == a || 0 == a.length) {
			return "null";
		}
		else if (1 == a.length) {
			return notNull (a [0]);
		}
		else {
			StringBuffer s = new StringBuffer (notNull (a [0])).append (BEGIN_LIST);
			for (int i = 1; i < a.length; i++) {
				s.append (notNull (a [i]));
				if (i < a.length - 1) {
					s.append(SEPARATOR);
				}
			}
			s.append(END_LIST);
			return s.toString();
		} 
	}


	// WARNING! copy-pasted methods below...
	
	public void error (Object [] a)
	{
		logger_.error (format (a));
	}
	
	public void error(Object arg0)
	{
		logger_.error(format (new Object [] {arg0}));
	}

	public void error (Object o1, Object o2)
	{
		logger_.error (format (new Object [] {o1, o2}));
	}
	

	public void error (Object o1, Object o2, Object o3)
	{
		logger_.error (format (new Object [] {o1, o2, o3}));
	}	
	
	public void debug (Object [] a)
	{
		if (isDebugEnabled()) {
			logger_.debug (format (a));
		}
	}

	public void debug(Object arg0)
	{
		if (isDebugEnabled()) {
			logger_.debug(format (new Object [] {arg0}));
		}
	}

	public void debug (Object o1, Object o2)
	{
		if (isDebugEnabled()) {
			logger_.debug (format (new Object [] {o1, o2}));
		}
	}


	public void debug (Object o1, Object o2, Object o3)
	{
		if (isDebugEnabled()) {
			logger_.debug (format (new Object [] {o1, o2, o3}));
		}
	}
	
	public void fatal (Object [] a)
	{
		logger_.fatal (format (a));
	}
	
	public void fatal(Object arg0)
	{
		logger_.fatal(format (new Object [] {arg0}));
	}

	public void fatal (Object o1, Object o2)
	{
		logger_.fatal (format (new Object [] {o1, o2}));
	}
	

	public void fatal (Object o1, Object o2, Object o3)
	{
		logger_.fatal (format (new Object [] {o1, o2, o3}));
	}
	
	public void info (Object [] a)
	{
		if (isInfoEnabled()) {
			logger_.info (format (a));
		}
	}

	public void info(Object arg0)
	{
		if (isInfoEnabled()) {
			logger_.info(format (new Object [] {arg0}));
		}
	}

	public void info (Object o1, Object o2)
	{
		if (isInfoEnabled()) {
			logger_.info (format (new Object [] {o1, o2}));
		}
	}


	public void info (Object o1, Object o2, Object o3)
	{
		if (isInfoEnabled()) {
			logger_.info (format (new Object [] {o1, o2, o3}));
		}
	}
	
	public void warn (Object [] a)
	{
		logger_.warn (format (a));
	}
	
	public void warn(Object arg0)
	{
		logger_.warn(format (new Object [] {arg0}));
	}

	public void warn (Object o1, Object o2)
	{
		logger_.warn (format (new Object [] {o1, o2}));
	}
	

	public void warn (Object o1, Object o2, Object o3)
	{
		logger_.warn (format (new Object [] {o1, o2, o3}));
	}

	public void error (Object [] a, Throwable e)
	{
		logger_.error (format (a), e);
	}

	public void error(Object arg0, Throwable arg1)
	{
		logger_.error(format (new Object [] {arg0}), arg1);
	}

	public void error (Object o1, Object o2, Throwable e)
	{
		logger_.error (format (new Object [] {o1, o2}), e);
	}
	

	public void error (Object o1, Object o2, Object o3, Throwable e)
	{
		logger_.error (format (new Object [] {o1, o2, o3}), e);
	}
	
	public void debug (Object [] a, Throwable e)
	{
		if (isDebugEnabled()) {
			logger_.debug (format (a), e);
		}
	}

	public void debug(Object arg0, Throwable arg1)
	{
		if (isDebugEnabled()) {
			logger_.debug(format (new Object [] {arg0}), arg1);
		}
	}

	public void debug (Object o1, Object o2, Throwable e)
	{
		if (isDebugEnabled()) {
			logger_.debug (format (new Object [] {o1, o2}), e);
		}
	}


	public void debug (Object o1, Object o2, Object o3, Throwable e)
	{
		if (isDebugEnabled()) {
			logger_.debug (format (new Object [] {o1, o2, o3}), e);
		}
	}

	public void fatal (Object [] a, Throwable e)
	{
		logger_.fatal (format (a), e);
	}

	public void fatal(Object arg0, Throwable arg1)
	{
		logger_.fatal(format (new Object [] {arg0}), arg1);
	}

	public void fatal (Object o1, Object o2, Throwable e)
	{
		logger_.fatal (format (new Object [] {o1, o2}), e);
	}
	

	public void fatal (Object o1, Object o2, Object o3, Throwable e)
	{
		logger_.fatal (format (new Object [] {o1, o2, o3}), e);
	}

	public void info (Object [] a, Throwable e)
	{
		if (isInfoEnabled()) {
		logger_.info (format (a), e);
		}
	}
	
	public void info(Object arg0, Throwable arg1)
	{
		if (isInfoEnabled()) {
			logger_.info(format (new Object [] {arg0}), arg1);
		}
	}

	public void info (Object o1, Object o2, Throwable e)
	{
		if (isInfoEnabled()) {
			logger_.info (format (new Object [] {o1, o2}), e);
		}
	}


	public void info (Object o1, Object o2, Object o3, Throwable e)
	{
		if (isInfoEnabled()) {
			logger_.info (format (new Object [] {o1, o2, o3}), e);
		}
	}

	public void warn (Object [] a, Throwable e)
	{
		logger_.warn (format (a), e);
	}
	
	public void warn(Object arg0, Throwable arg1)
	{
		logger_.warn(format (new Object [] {arg0}), arg1);
	}

	public void warn (Object o1, Object o2, Throwable e)
	{
		logger_.warn (format (new Object [] {o1, o2}), e);
	}
	

	public void warn (Object o1, Object o2, Object o3, Throwable e)
	{
		logger_.warn (format (new Object [] {o1, o2, o3}), e);
	}

	public boolean isDebugEnabled()
	{
		return logger_.isDebugEnabled();
	}

	 public boolean isInfoEnabled()
	 {
	     return this.logger_.isInfoEnabled();
	 }
}
